package com.atguigu.tingshu.handler;

import com.atguigu.tingshu.entity.CDCEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;
import top.javatool.canal.client.annotation.CanalTable;
import top.javatool.canal.client.handler.EntryHandler;

@CanalTable("album_info")
@Component
@Slf4j
public class AlbumInfoCdcHandler implements EntryHandler<CDCEntity> {
    @Autowired
    private RedisTemplate redisTemplate;



    @Override
    public void insert(CDCEntity cdcEntity) {
        EntryHandler.super.insert(cdcEntity);
    }

    @Override
    public void update(CDCEntity before, CDCEntity after) {
        log.info("更新了专辑信息before:{}",before.getId());
        log.info("更新了专辑信息after:{}",after.getId());
        try {
            String key = "album:info:[" + after.getId() + "]";
            redisTemplate.delete(key);
        } catch (Exception e) {
            log.error("更新专信息失败：{}",e.getMessage());
            System.out.println(e.getMessage());
        }
        EntryHandler.super.update(before, after);
    }

    @Override
    public void delete(CDCEntity cdcEntity) {
        EntryHandler.super.delete(cdcEntity);
    }
}
